package com.java.escape.springproblem.transaction;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.io.InputStream;
import java.io.Reader;

/**
 * @ClassName SpringTransactionImpl
 * @Description TODO
 * @Author wyp
 * @Date 2023/9/13 10:25
 * @Version 1.0
 */
@Service
public class SpringTransactionImpl {


    @Transactional
    public void canRollback() {
        try {
            System.out.println("       ");
            throw new RuntimeException();
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            String currentTransactionName = TransactionSynchronizationManager.getCurrentTransactionName();
            System.out.println(currentTransactionName);
        }
    }
}
